package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

// @Controller
// @ResponseBody
@RestController
@RequestMapping("/user")
public class UserController {

    //rest风格访问路径完整书写方式
    @RequestMapping("/restLocation")
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String restLocation(){
        System.out.println("restful is running ....");
        return "success.jsp";
    }

    // 第一个restful风格
    // /user/1
    // @RequestMapping("/user/{id}")
    @RequestMapping("{id}")
    // @ResponseBody
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String restLocation(@PathVariable Integer id){
        System.out.println("restful is running ....get:"+id);
        return "success.jsp";
    }

    // @RequestMapping(value = "{id}",method = RequestMethod.GET)
    @GetMapping("{id}")
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String get(@PathVariable Integer id){
        System.out.println("restful is running ....get:"+id);
        return "success.jsp";
    }

    // @RequestMapping(value = "{id}",method = RequestMethod.POST)
    @PostMapping("{id}")
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String post(@PathVariable Integer id){
        System.out.println("restful is running ....post:"+id);
        return "success.jsp";
    }

    // @RequestMapping(value = "{id}",method = RequestMethod.PUT)
    @PutMapping("{id}")
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String put(@PathVariable Integer id){
        System.out.println("restful is running ....put:"+id);
        return "success.jsp";
    }

    // @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    @DeleteMapping("{id}")
    //使用@PathVariable注解获取路径上配置的具名变量，该配置可以使用多次
    public String delete(@PathVariable Integer id){
        System.out.println("restful is running ....delete:"+id);
        return "success.jsp";
    }
/**
 * 缩略配置方式
 * @GetMapping("{id}") == @RequestMapping(value = "{id}",method = RequestMethod.GET)
 */
}
